import os
from flask import Flask
from flask_socketio import SocketIO  # pip install flask-socketio
import sys
sys.path.append(os.path.join(sys.path[0], '..'))  # 调用父目录下的模块
from py_at.py_at_adapter_test import *



app = Flask(__name__, static_url_path='')  # 创建 flask application 对象
socketio = SocketIO(app, async_mode=None, engineio_logger=False)  # eventlet存在多次连接不断开的现象
@socketio.on_error()
def error_handler(e):
    print("error:" + e)




# ----------------------------------------------普通调用

a = AdapterTest()
# a.Canshus = [{'id': 'rb5-101', 'strategy': 'Aberration', 'Instrument': 'rb1710', 'Interval': 30,
#               'IntervalType': IntervalType.Minute, 'BeginDate': '20170418', 'EndDate':'20170726','Params': {'Length1': 35, 'StdDevUp': 0.5,'StdDevDn': 0.5, 'Lots': 1}}]
# ---------------------------------------------

# ---------------------------------------------rpc调用
'''
from py_at.rpc.client import *
reqAddress = 'tcp://localhost:2014'
subAddress = 'tcp://localhost:0602'
ene = enentE()
a = MainEngineProxy(ene)
a.init(reqAddress, subAddress)
'''

# ----------------------------------------------------------------------------------------------------------------------


a.load_strategy_json()  # 加载策略配置文件
a.load_strategyname()  # 加载所有策略类名
a.load_all_Instrument()  # 加载所有合约信息
a.createlogInfo()        #日志初始化



from web_flask.app import socket                       #加载socket

# 以下为需要加载的模块  注意加载次序  必须等待上面都加载完毕以后才能加载下面
from web_flask.app import router



# # socket.io通用处理
# from web_flask.app import shfe_depth
#
# # ctp封装
# from web_flask.app import ctp_socketio
#
# #dome 封装
# from web_flask.app import ctp_onDome
